


***********************************************************************************************************************************************************************************************
****NOW USE 3 SUPERGROUPS (FRESH FOOD, PROCESSED FOOD, NON-FOOD) WITH 8 SUBGROUPS TO ORGANIZE COMBINATORIALS***********************************************************************************
***********************************************************************************************************************************************************************************************
**********GENERATE 2^4-1=15 POSSIBLE GROUPINGS OF FRESH FOOD (SPLITTING INTO 2 OR 1 GS) TIMES (n^3-1=7) POSSIBLE GROUPINGS OF PROCESSED (1 or 2 Gs) TIMES 1 GROUPING OF NON-FOOD (TOTAL=105)***
***********************************************************************************************************************************************************************************************
******THIS LEADS TO 3-5 Gs IN TOTAL ACROSS THE 105 (15*7*1) WAYS OF SPLITTING UP THE SUBGROUPS*************************************************************************************************
******ADD TO THAT THREE OTHER POSSIBILITIES: ONE WITH ONLY ONE G, ONE WITH ONLY 2 G (FOOD/NON-FOOD), AND ONE WITH 8 Gs*************************************************************************
******TOTAL COMES UP TO 108 POSSIBLE G-GROUPINGS TO LOOP OVER (INCLUDING OUR 3 Gs THAT WE HAVE IN THE BASELINE*********************************************************************************
***********************************************************************************************************************************************************************************************

clear all
set more off

input str10 G_name

"cereals"
"fruits"
"gram"
"meat"


end

compress


tuples cereals fruits gram meat
macro list

forvalues i=1(1)15 {

gen tuple`i'="`tuple`i''"

}
*

forvalues i=1(1)15 {

gen G_`i'=2 if (G_name==word(tuple`i',1) | G_name==word(tuple`i',2) | G_name==word(tuple`i',3) | G_name==word(tuple`i',4))

}
*

drop tuple1-tuple15


mvencode G_1-G_15, mv(1)

compress

set obs 8

gsort - G_name
egen seq=seq()
replace G_name="milk" if seq==5
replace G_name="sugar" if seq==6 
replace G_name="refresh" if seq==7
replace G_name="fuels" if seq==8 
drop seq

forvalues i=1(1)15 {

replace G_`i'=3 if (G_name=="milk" | G_name=="refresh" | G_name=="sugar")
replace G_`i'=5 if G_name=="fuels"
}
*

compress

cd "$master_file_path/data/intermediate_data/Alternative_Gs"
save G_Groupings_108, replace


preserve

forvalues i=1(1)15 {
local bla=`i'+15
replace G_`i'=4 if (G_name=="milk")
rename G_`i' G_`bla' 
}
*

merge 1:1 G_name using G_Groupings_108
drop _merge

compress
save G_Groupings_108, replace
restore

preserve

forvalues i=1(1)15 {
local bla=`i'+30
replace G_`i'=4 if (G_name=="refresh")
rename G_`i' G_`bla' 
}
*

merge 1:1 G_name using G_Groupings_108
drop _merge

compress
save G_Groupings_108, replace
restore

preserve

forvalues i=1(1)15 {
local bla=`i'+45
replace G_`i'=4 if (G_name=="sugar")
rename G_`i' G_`bla' 
}
*

merge 1:1 G_name using G_Groupings_108
drop _merge

compress
save G_Groupings_108, replace
restore

preserve

forvalues i=1(1)15 {
local bla=`i'+60
replace G_`i'=4 if (G_name=="milk" | G_name=="refresh")
rename G_`i' G_`bla' 
}
*

merge 1:1 G_name using G_Groupings_108
drop _merge

compress
save G_Groupings_108, replace
restore

preserve

forvalues i=1(1)15 {
local bla=`i'+75
replace G_`i'=4 if (G_name=="milk" | G_name=="sugar")
rename G_`i' G_`bla' 
}

sleep 5000

merge 1:1 G_name using G_Groupings_108
drop _merge

compress
save G_Groupings_108, replace
restore

forvalues i=1(1)15 {
local bla=`i'+90
replace G_`i'=4 if (G_name=="sugar" | G_name=="refresh")
rename G_`i' G_`bla' 
}
*

merge 1:1 G_name using G_Groupings_108
drop _merge

compress

gen G_106=1
gen G_107=1
replace G_107=2  if G_name=="fuels"
egen G_108=seq()
compress

save G_Groupings_108, replace

rename G_name g_groups_8

merge 1:m g_groups_8 using "$master_file_path/data/source_data/Item_Group_Concordance.dta", keepusing(i_products)
drop _merge

rename g_gr G_name

order i_products G_name

compress

save G_Groupings_108, replace

clear all

